#include "Agents/Agent.hpp"
#include "AgentBody.hpp"


AgentBody::~AgentBody(){
    std::cout<<"Destruction AgentBody"<<std::endl;
    if (m_motionInfluence != NULL)
        delete m_motionInfluence;
}

//Création de l'influence du body
void AgentBody::influence(Vector2D *linearInfluence, double angularInfluence)
{
    Vector2D *lInfluence;
    if(linearInfluence != NULL){
        lInfluence = new Vector2D(*linearInfluence);
        double nSpeed = linearInfluence->length();
        if(nSpeed > 10){ //comparer à maxlinearAcc
            lInfluence->normalize();
            //scale lInfluence avec maxlinearacc
            lInfluence->setX(lInfluence->x()*10);
            lInfluence->setY(lInfluence->y()*10);
        }
    }
    else{
        lInfluence = new Vector2D();
    }
    //10 à remplacer par maxangularacc
    double aInfluence;
    if (angularInfluence<-10)
        aInfluence=-10;
    else if(angularInfluence>10)
        aInfluence=10;
    else
        aInfluence = angularInfluence;

    m_motionInfluence = new Influence(this,lInfluence,aInfluence);

}

void AgentBody::removeInfluence(){
    std::cout<<"Remove Influence"<<std::endl;
    delete m_motionInfluence;
    m_motionInfluence = NULL;
}

bool AgentBody::exist() {
    if (!this)
        return false;
    return true;
}

void AgentBody::setObjectsPerceived(std::vector<Perception*> objPerceived){this->m_objectsPerceived = objPerceived;}

std::vector<Perception*> AgentBody::getObjectsPerceived() { return m_objectsPerceived; }
